package org.sikyon.chocolatebiscuit.services.server;

import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Scopes;
import com.google.inject.servlet.GuiceServletContextListener;
import com.sun.jersey.guice.JerseyServletModule;
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
import org.sikyon.chocolatebiscuit.services.PingService;

// TODO change the name of this class once I have understood what it <i>really</i> does
public class HelloGuiceServletConfig extends GuiceServletContextListener {

    @Override
    protected Injector getInjector() {
        return Guice.createInjector(new JerseyServletModule() {
            @Override
            protected void configureServlets() {
                // hook Jackson into Jersey
                bind(JacksonJsonProvider.class).in(Scopes.SINGLETON);

                // hook the services
                bind(PingService.class);

                // tell guice to serve the root path // TODO change this for "/rest"?
                serve("/*").with(GuiceContainer.class);
            }
        });
    }
}
